<template>
  <div class="sys-server-page">
    <el-card
      class="aui-card--fill"
      shadow="never">
      <div class="mod-sys__user">
        <el-form
          :inline="true"
          :model="dataForm"
          @keyup.enter.native="getDataList()">
          <el-form-item>
            <el-input
              :placeholder="$t('monitor.ip')"
              clearable
              v-model="dataForm.ip"/>
          </el-form-item>
          <el-form-item>
            <el-button @click="getDataList()">{{ $t('query') }}</el-button>
          </el-form-item>
          <!--                    新增-->
          <el-form-item>
            <el-button
              @click="addOrUpdateHandle()"
              type="primary"
              v-if="$hasPermission('monitor:mmonitoriplist:save')">{{ $t('add') }}
            </el-button>
          </el-form-item>

          <!--                    删除-->
          <!--                    <el-form-item>-->
          <!--                        <el-button v-if="$hasPermission('sys:user:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>-->
          <!--                    </el-form-item>-->
          <!--                    导出 -->
          <!--                    <el-form-item>-->
          <!--                        <el-button v-if="$hasPermission('sys:user:export')" type="info" @click="exportHandle()">{{ $t('export') }}</el-button>-->
          <!--                    </el-form-item>-->
        </el-form>
        <el-table
          :data="dataList"
          @selection-change="dataListSelectionChangeHandle"
          @sort-change="dataListSortChangeHandle"
          border
          style="width: 100%;"
          v-loading="dataListLoading">
          <el-table-column
            align="center"
            header-align="center"
            type="selection"
            width="50"/>
          <el-table-column
            :label="$t('monitor.ip')"
            align="center"
            header-align="center"
            prop="ip"/>
          <el-table-column
            :label="$t('monitor.leader')"
            align="center"
            header-align="center"
            prop="leader"
            sortable="custom"/>

          <el-table-column
            :label="$t('monitor.apiMonitor')"
            align="center"
            header-align="center"
            prop="apiMonitor"
            sortable="custom">
            <template slot-scope="scope">
              <el-tag
                size="small"
                type="success"
                v-if="scope.row.apiMonitor">{{ $t('monitor.yes') }}
              </el-tag>
              <el-tag
                size="small"
                type="danger"
                v-else>{{ $t('monitor.no') }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            :label="$t('monitor.diskMonitor')"
            align="center"
            header-align="center"
            prop="diskMonitor"
            sortable="custom">
            <template slot-scope="scope">
              <el-tag
                size="small"
                type="success"
                v-if="scope.row.diskMonitor">{{ $t('monitor.yes') }}
              </el-tag>
              <el-tag
                size="small"
                type="danger"
                v-else>{{ $t('monitor.no') }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            :label="$t('monitor.processMonitor')"
            align="center"
            header-align="center"
            prop="processMonitor"
            sortable="custom">
            <template slot-scope="scope">
              <el-tag
                size="small"
                type="success"
                v-if="scope.row.processMonitor">{{ $t('monitor.yes') }}
              </el-tag>
              <el-tag
                size="small"
                type="danger"
                v-else>{{ $t('monitor.no') }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            :label="$t('monitor.memoryMonitor')"
            align="center"
            header-align="center"
            prop="memoryMonitor"
            sortable="custom">
            <template slot-scope="scope">
              <el-tag
                size="small"
                type="success"
                v-if="scope.row.memoryMonitor">{{ $t('monitor.yes') }}
              </el-tag>
              <el-tag
                size="small"
                type="danger"
                v-else>{{ $t('monitor.no') }}</el-tag>
            </template>
          </el-table-column>

          <el-table-column
            :label="$t('monitor.status')"
            align="center"
            header-align="center"
            prop="status"
            sortable="custom">
            <template slot-scope="scope">
              <el-tag
                size="small"
                type="success"
                v-if="scope.row.status">{{ $t('user.status1') }}
              </el-tag>
              <el-tag
                size="small"
                type="danger"
                v-else>{{ $t('user.status0') }}</el-tag>
            </template>
          </el-table-column>
          <!--                    <el-table-column prop="createDate" :label="$t('user.createDate')" sortable="custom" header-align="center" align="center" width="180"></el-table-column>-->
          <el-table-column
            :label="$t('handle')"
            align="center"
            fixed="right"
            header-align="center"
            width="150">
            <template slot-scope="scope">
              <el-button
                @click="addOrUpdateHandle(scope.row.id)"
                size="small"
                type="primary"
                v-if="$hasPermission('monitor:mmonitoriplist:update')">{{ $t('update') }}
              </el-button>
              <el-button
                @click="deleteHandle(scope.row.id)"
                size="small"
                type="danger"
                v-if="$hasPermission('monitor:mmonitoriplist:delete')">{{ $t('delete') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="page"
          :page-size="limit"
          :page-sizes="[10, 20, 50, 100]"
          :total="total"
          @current-change="pageCurrentChangeHandle"
          @size-change="pageSizeChangeHandle"
          layout="total, sizes, prev, pager, next, jumper"/>
        <!-- 弹窗, 新增 / 修改 -->
        <add-or-update
          @refreshDataList="getDataList"
          ref="addOrUpdate"
          v-if="addOrUpdateVisible"/>
      </div>
    </el-card>

  </div>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './server-add-or-update'

export default {
  name: 'Server',
  mixins: [mixinViewModule],
  components: {
    AddOrUpdate
  },

  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/monitor/mmonitoriplist/page',
        getDataListIsPage: true,
        deleteURL: '/monitor/mmonitoriplist/',
        deleteIsBatch: true
        // exportURL: '/sys/user/export'
      },
      dataForm: {
        ip: ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>

    .sys-server-page {

    }
</style>
